﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Reflection;

namespace FinancialDB
{
    public partial class home_Form : Form
    {
        private PictureBox lastClick;

        public home_Form()
        {
            InitializeComponent();
        }

        private void home_Form_Load(object sender, EventArgs e)
        {
            XmlDocument xmldoc = new XmlDocument();
            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"FinancialDB.Users.userdata.xml");
            xmldoc.Load(stream);
            XmlNode firstpage = xmldoc.SelectSingleNode("/root/firstpage");
            if (firstpage != null)
            {
                String name = firstpage.Attributes["name"].Value;
                Form form = null;

                if (name == "fx")
                {
                    this.pictureBox1.Image = global::FinancialDB.Properties.Resources.外汇2;
                    lastClick = pictureBox1;
                    form = new home_FX_Panel();
                }
                else if(name == "bond")
                {
                    this.pictureBox2.Image = global::FinancialDB.Properties.Resources.债券2;
                    this.pictureBox1.Image = global::FinancialDB.Properties.Resources.外汇3;
                    lastClick = pictureBox2;
                    form = new home_Bond_Panel();
                }
                else if (name == "commodity")
                {
                    this.pictureBox3.Image = global::FinancialDB.Properties.Resources.大宗商品2;
                    this.pictureBox2.Image = global::FinancialDB.Properties.Resources.债券3;
                    lastClick = pictureBox3;
                    form = new home_Commodity_Panel();
                }
                else if (name == "stock")
                {
                    this.pictureBox4.Image = global::FinancialDB.Properties.Resources.股票2;
                    this.pictureBox3.Image = global::FinancialDB.Properties.Resources.大宗商品3;
                    lastClick = pictureBox4;
                    form = new home_Stock_Panel();
                }
                else if (name == "fm")
                {
                    this.pictureBox5.Image = global::FinancialDB.Properties.Resources.理财2;
                    this.pictureBox4.Image = global::FinancialDB.Properties.Resources.股票3;
                    lastClick = pictureBox5;
                    form = new home_FM_Panel();
                }
                else if (name == "futures")
                {
                    this.pictureBox6.Image = global::FinancialDB.Properties.Resources.期货2;
                    this.pictureBox5.Image = global::FinancialDB.Properties.Resources.理财3;
                    lastClick = pictureBox6;
                    form = new home_Futures_Panel();
                }
                else if (name == "derivatives")
                {
                    this.pictureBox7.Image = global::FinancialDB.Properties.Resources.衍生品2;
                    this.pictureBox6.Image = global::FinancialDB.Properties.Resources.期货3;
                    lastClick = pictureBox7;
                    form = new home_Derivatives_Panel();
                }
                else if (name == "macro")
                {
                    this.pictureBox8.Image = global::FinancialDB.Properties.Resources.宏观经济2;
                    this.pictureBox7.Image = global::FinancialDB.Properties.Resources.衍生品3;
                    lastClick = pictureBox8;
                    form = new home_Macro_Panel();
                }
                else if (name == "industry")
                {
                    this.pictureBox9.Image = global::FinancialDB.Properties.Resources.行业经济2;
                    this.pictureBox8.Image = global::FinancialDB.Properties.Resources.宏观经济3;
                    lastClick = pictureBox9;
                    form = new home_Industry_Panel();
                }
                else if (name == "hf")
                {
                    this.pictureBox10.Image = global::FinancialDB.Properties.Resources.高频数据2;
                    this.pictureBox9.Image = global::FinancialDB.Properties.Resources.行业经济3;
                    lastClick = pictureBox10;
                    form = new home_HF_Panel();
                }
                else
                {
                    this.pictureBox11.Image = global::FinancialDB.Properties.Resources.我的主页2;
                    this.pictureBox10.Image = global::FinancialDB.Properties.Resources.高频数据3;
                    lastClick = pictureBox11;
                    form = new home_Homepage_Panel();
                }

                form.TopLevel = false;
                form.FormBorderStyle = FormBorderStyle.None;
                form.Dock = System.Windows.Forms.DockStyle.Fill;
                this.mid_panel.Controls.Add(form);
                form.Show();
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            Form form = new home_FX_Panel();

            this.mid_panel.Controls.Clear();

            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mid_panel.Controls.Add(form);
            form.Show();

            restoreLastClick();
            
            PictureBox pb = sender as PictureBox;
            pb.Image = global::FinancialDB.Properties.Resources.外汇2;
            lastClick = pb;
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            Form form = new home_Bond_Panel();

            this.mid_panel.Controls.Clear();

            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mid_panel.Controls.Add(form);
            form.Show();

            restoreLastClick();

            PictureBox pb = sender as PictureBox;
            pb.Image = global::FinancialDB.Properties.Resources.债券2;
            this.pictureBox1.Image = global::FinancialDB.Properties.Resources.外汇3;
            lastClick = pb;
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            Form form = new home_Commodity_Panel();

            this.mid_panel.Controls.Clear();

            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mid_panel.Controls.Add(form);
            form.Show();

            restoreLastClick();

            PictureBox pb = sender as PictureBox;
            pb.Image = global::FinancialDB.Properties.Resources.大宗商品2;
            this.pictureBox2.Image = global::FinancialDB.Properties.Resources.债券3;
            lastClick = pb;
        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            Form form = new home_Stock_Panel();

            this.mid_panel.Controls.Clear();

            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mid_panel.Controls.Add(form);
            form.Show();

            restoreLastClick();

            PictureBox pb = sender as PictureBox;
            pb.Image = global::FinancialDB.Properties.Resources.股票2;
            this.pictureBox3.Image = global::FinancialDB.Properties.Resources.大宗商品3;
            lastClick = pb;
        }

        private void pictureBox5_Click(object sender, EventArgs e)
        {
            Form form = new home_FM_Panel();

            this.mid_panel.Controls.Clear();

            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mid_panel.Controls.Add(form);
            form.Show();

            restoreLastClick();

            PictureBox pb = sender as PictureBox;
            pb.Image = global::FinancialDB.Properties.Resources.理财2;
            this.pictureBox4.Image = global::FinancialDB.Properties.Resources.股票3;
            lastClick = pb;
        }

        private void pictureBox6_Click(object sender, EventArgs e)
        {
            Form form = new home_Futures_Panel();

            this.mid_panel.Controls.Clear();

            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mid_panel.Controls.Add(form);
            form.Show();

            restoreLastClick();

            PictureBox pb = sender as PictureBox;
            pb.Image = global::FinancialDB.Properties.Resources.期货2;
            this.pictureBox5.Image = global::FinancialDB.Properties.Resources.理财3;
            lastClick = pb;
        }

        private void pictureBox7_Click(object sender, EventArgs e)
        {
            Form form = new home_Derivatives_Panel();

            this.mid_panel.Controls.Clear();

            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mid_panel.Controls.Add(form);
            form.Show();

            restoreLastClick();

            PictureBox pb = sender as PictureBox;
            pb.Image = global::FinancialDB.Properties.Resources.衍生品2;
            this.pictureBox6.Image = global::FinancialDB.Properties.Resources.期货3;
            lastClick = pb;
        }

        private void pictureBox8_Click(object sender, EventArgs e)
        {
            Form form = new home_Macro_Panel();

            this.mid_panel.Controls.Clear();

            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mid_panel.Controls.Add(form);
            form.Show();

            restoreLastClick();

            PictureBox pb = sender as PictureBox;
            pb.Image = global::FinancialDB.Properties.Resources.宏观经济2;
            this.pictureBox7.Image = global::FinancialDB.Properties.Resources.衍生品3;
            lastClick = pb;
        }

        private void pictureBox9_Click(object sender, EventArgs e)
        {
            Form form = new home_Industry_Panel();

            this.mid_panel.Controls.Clear();

            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mid_panel.Controls.Add(form);
            form.Show();

            restoreLastClick();

            PictureBox pb = sender as PictureBox;
            pb.Image = global::FinancialDB.Properties.Resources.行业经济2;
            this.pictureBox8.Image = global::FinancialDB.Properties.Resources.宏观经济3;
            lastClick = pb;
        }

        private void pictureBox10_Click(object sender, EventArgs e)
        {
            Form form = new home_HF_Panel();

            this.mid_panel.Controls.Clear();

            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mid_panel.Controls.Add(form);
            form.Show();

            restoreLastClick();

            PictureBox pb = sender as PictureBox;
            pb.Image = global::FinancialDB.Properties.Resources.高频数据2;
            this.pictureBox9.Image = global::FinancialDB.Properties.Resources.行业经济3;
            lastClick = pb;
        }

        private void pictureBox11_Click(object sender, EventArgs e)
        {
            Form form = new home_Homepage_Panel();

            this.mid_panel.Controls.Clear();

            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Dock = System.Windows.Forms.DockStyle.Fill;
            this.mid_panel.Controls.Add(form);
            form.Show();

            restoreLastClick();

            PictureBox pb = sender as PictureBox;
            pb.Image = global::FinancialDB.Properties.Resources.我的主页2;
            this.pictureBox10.Image = global::FinancialDB.Properties.Resources.高频数据3;
            lastClick = pb;
        }

        private void restoreLastClick()
        {
            if (lastClick != null)
            {
                if (lastClick.Name.Equals("pictureBox1"))
                {
                    this.pictureBox1.Image = global::FinancialDB.Properties.Resources.外汇;
                    this.pictureBox2.Image = global::FinancialDB.Properties.Resources.债券;
                } 
                else if (lastClick.Name.Equals("pictureBox2"))
                {
                    this.pictureBox1.Image = global::FinancialDB.Properties.Resources.外汇;
                    this.pictureBox2.Image = global::FinancialDB.Properties.Resources.债券;
                }
                else if (lastClick.Name.Equals("pictureBox3"))
                {
                    this.pictureBox2.Image = global::FinancialDB.Properties.Resources.债券;
                    this.pictureBox3.Image = global::FinancialDB.Properties.Resources.大宗商品;
                }
                else if (lastClick.Name.Equals("pictureBox4"))
                {
                    this.pictureBox3.Image = global::FinancialDB.Properties.Resources.大宗商品;
                    this.pictureBox4.Image = global::FinancialDB.Properties.Resources.股票;
                }
                else if (lastClick.Name.Equals("pictureBox5"))
                {
                    this.pictureBox4.Image = global::FinancialDB.Properties.Resources.股票;
                    this.pictureBox5.Image = global::FinancialDB.Properties.Resources.理财;
                }
                else if (lastClick.Name.Equals("pictureBox6"))
                {
                    this.pictureBox5.Image = global::FinancialDB.Properties.Resources.理财;
                    this.pictureBox6.Image = global::FinancialDB.Properties.Resources.期货;
                }
                else if (lastClick.Name.Equals("pictureBox7"))
                {
                    this.pictureBox6.Image = global::FinancialDB.Properties.Resources.期货;
                    this.pictureBox7.Image = global::FinancialDB.Properties.Resources.衍生品;
                }
                else if (lastClick.Name.Equals("pictureBox8"))
                {
                    this.pictureBox7.Image = global::FinancialDB.Properties.Resources.衍生品;
                    this.pictureBox8.Image = global::FinancialDB.Properties.Resources.宏观经济;
                }
                else if (lastClick.Name.Equals("pictureBox9"))
                {
                    this.pictureBox8.Image = global::FinancialDB.Properties.Resources.宏观经济;
                    this.pictureBox9.Image = global::FinancialDB.Properties.Resources.行业经济;
                }
                else if (lastClick.Name.Equals("pictureBox10"))
                {
                    this.pictureBox9.Image = global::FinancialDB.Properties.Resources.行业经济;
                    this.pictureBox10.Image = global::FinancialDB.Properties.Resources.高频数据;
                }
                else if (lastClick.Name.Equals("pictureBox11"))
                {
                    this.pictureBox10.Image = global::FinancialDB.Properties.Resources.高频数据;
                    this.pictureBox11.Image = global::FinancialDB.Properties.Resources.我的主页;
                }
            }
        }
    }
}
